package com.aji.alluser.mapper;


import com.aji.alluser.domain.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LoginMapper {
    @Select("select * from user where username = #{username}")
    User getByUserName(String username);
    @Select("select * from user where id = #{userId}")
    User getByUserId(Long userId);
    @Select("        select distinct m.menu_name\n" +
            "        from\n" +
            "            role_user\n" +
            "                left join role r on r.id = role_user.role_id\n" +
            "                left join role_menu rm on r.id = rm.role_id\n" +
            "                left join menu m on rm.menu_id = m.id\n" +
            "        where user_id = #{id}")
    List<String> selectPermsByUserId(Long id);

    @Select("select role_name from role\n" +
            "left join role_user ru on role.id = ru.role_id\n" +
            "where ru.user_id =#{id}")
    List<String> getRoleById(Long id);

    @Select("SELECT r.role_name FROM role_user ur JOIN role r ON ur.role_id = r.id WHERE ur.user_id = #{userId}")
    List<String> selectRolesByUserId(@Param("userId") long userId);
}
